package com.sk.skplanet.commute.views;

import java.io.File;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.LoadingTask;
import com.sk.skplanet.commute.actions.SQLiteTask;
import com.sk.skplanet.commute.daofactory.LocalDaoFactory;
import com.sk.skplanet.commute.vo.Data;


public class SplashActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splashactivity);
		Handler handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {

				Intent i = new Intent(SplashActivity.this, MemberLogin.class);
				File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + Data.FilePATH);
				if (!dir.exists()) dir.mkdirs();
				File target = new File(dir.getAbsolutePath() + Data.FileNAME);
				if (!target.exists()) {
					startActivity(i);
					finish();
				} else {// Local DB
						// new LocalDaoFactory();
					String authKey = new SQLiteTask().getAuthKey();
					// authKey = "";
					// Log.i("key", "" + authKey);
					if ("".equals(authKey) || authKey == null) {
						startActivity(i);
						finish();
					} else {
						new LoadingTask(SplashActivity.this, authKey).execute();
					}
				}

			}
		};
		handler.sendEmptyMessageDelayed(0, Data.splashTime);

	}
}
